# Model predictive control (MPC)-based irrigation scheduler for a sandy clay loam field

## Introduction
This python code demonstrates how an MPC based irrigation scheduler can be designed for a homogeneous field. The main code can be found in the **main_cl_scheduler.py** file. There exists other files which contain 
functions that are employed by the main code. Appropriate descriptions and comments have been provided in each file. The code also provides the weights and biases of a sample LSTM model that was identified for the investigated field
and these can be found in the **weights_casestudy** folder. The uncontrolled inputs and the initial states can be found in text files located in the **uncontrolled_inputs** folder. The results obtained after running the main code
can be found in the **test_casestudy_results** folder.

## Requirements
This code requires **Python 3** as well as some other relevant packages such as **numpy, scipy, casadi**, etc. The configuration file, **environment.yml**, of a conda environment which contains the required packages has been provided. 
This environment can be created by executing the following line in the Anaconda command prompt or any suitable shell

``` 
conda env create -f environment.yml
```
Running the above command will create a conda environment named **tf**.


## Usage 
Firstly, one will have to activate a python environment that contains the required packages. For example, the **tf** environment can be activated as follows

```
conda activate tf
```

Next, to run the closed-loop irigation scheduler, the **main_cl_scheduler.py** can be executed in any python IDE. Alternatively, command line enthusiats may execute the following line

```
python main_cl_scheduler.py
```

## Feedback
Please get in touch via [mail](mailto:jinfeng@ualberta.ca) if you have questions.



